package Client.PokerClient.src;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

/**
 * Klasa Listenera dla klasy CreateGameWindow.
 * @author Xsar
 */
public class CreateGameListener implements ActionListener {
  /**
   * Referencja do glownego programu.
   */
  private Client client;
  /**
   * Referencja do okna createGameWindow.
   */
  private CreateGameWindow createGameWindow;
  /**
   * Konsturktor klasy.
   * @param client Referencja do glownej klasy programu.
   * @param createGameWindow Referencja do okna createGameWindow.
   */
  CreateGameListener(Client client, CreateGameWindow createGameWindow) {
    this.client=client;
    this.createGameWindow=createGameWindow;
  }
  /**
   * Metoda zajmujaca sie zdarzeniami wystepujacymi w klasie CreateGameWindow.	
   */
  public void actionPerformed(ActionEvent e) {
    if(e.getSource() == this.createGameWindow.getBack()) {
	  client.getCreateGameWindow().dispose();
	  client.getMainWindow().setEnabled(true);
	  client.getMainWindow().toFront();
	}
	if(e.getSource() == this.createGameWindow.getCreateGame()) {
      if(createGameWindow.getNumberOfPlayers()>createGameWindow.getNumberOfBot()&&createGameWindow.ifHostPlay()==1)
	    client.getServerController().S_NEWGAME(createGameWindow.getNumberOfPlayers(), createGameWindow.getNumberOfBot(), createGameWindow.ifHostPlay());
	  else if(createGameWindow.getNumberOfPlayers()>=createGameWindow.getNumberOfBot()&&createGameWindow.ifHostPlay()==0)
		client.getServerController().S_NEWGAME(createGameWindow.getNumberOfPlayers(), createGameWindow.getNumberOfBot(), createGameWindow.ifHostPlay());
	  else
		JOptionPane.showMessageDialog(null, "Podano nieprawidlowe dane");

      client.getCreateGameWindow().dispose();
	  client.getMainWindow().setEnabled(true);
	  client.getMainWindow().toFront();
	}
  }
}
